package com.xinzhiduming.listviewadapter;

import java.util.ArrayList;
import com.xinzhiduming.weatherinfo.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class SelectCityListViewAdapter extends BaseAdapter{
	LayoutInflater mLayoutInflater = null;
	ArrayList<String> mCityName = new ArrayList<String>();
	
	public SelectCityListViewAdapter(Context context, ArrayList<String> arrayList) {
		mLayoutInflater = LayoutInflater.from(context);
		mCityName = arrayList;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mCityName.size();
	}

	@Override
	public String getItem(int position) {
		// TODO Auto-generated method stub
		return mCityName.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHoler viewHoler;
		if (convertView == null) {
			viewHoler = new ViewHoler();
			convertView = mLayoutInflater.inflate(R.layout.select_city_list_view_detail, null);
			viewHoler.mCityNameTv = (TextView) convertView.findViewById(R.id.city_name_tv);
			convertView.setTag(viewHoler);
		} else {
			viewHoler = (ViewHoler) convertView.getTag();
		}
		viewHoler.mCityNameTv.setText(mCityName.get(position));
		return convertView;
	}
	
	static class ViewHoler {
		public TextView mCityNameTv;
	}
}
